package com.chenshuang.web;

import com.chenshuang.bean.Goods;
import com.chenshuang.service.GoodsService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "DetailsServlet", value = "/details")
public class DetailsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取id
        String id = request.getParameter("id");
        // 业务层 根据id查询 商品所有信息 返回给商品对象
        GoodsService goodsService = new GoodsService();
        Goods goods = goodsService.queryGoods(id);

        request.setAttribute("goods",goods);
        request.getRequestDispatcher("WEB-INF/details.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
